package wiiusej.activeTaskManagement;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class SharedCell {

	
	//Write-Read Lock System
    private final ReadWriteLock lock = new ReentrantReadWriteLock();
    
	//Locks for wiimotes structure
    private final Lock wiimotesR = lock.readLock();
    private final Lock wiimotesW = lock.writeLock();
    
    //Log
    static Logger fileLogger;
    
    private int frequencyMillis = 0;
	
	
	public SharedCell(int initialFreq){
		
		PropertyConfigurator.configure("log4j.properties");
		this.fileLogger = Logger.getLogger("speaker");
		
		this.frequencyMillis = initialFreq;
		
	}
	
	
	public int getFrequencyMillis() {
		wiimotesR.lock();		
		try{
			//fileLogger.info("Current Frequency Got: " + soundFrequencyMillis);
			return frequencyMillis;			
		}finally{
			wiimotesR.unlock();
		}	
		
	}
	
	public void setFrequencyMillis(int soundFrequencyMillis) {
		wiimotesW.lock();		
		try{
			//fileLogger.info("Current Frequency Set: " + soundFrequencyMillis);
			this.frequencyMillis = soundFrequencyMillis;;			
		}finally{
			wiimotesW.unlock();
		}
	}

}
